package com.hetao.xx.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.GridView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.hetao.xx.R;
import com.hetao.xx.adapter.LoadPageAdapter;
import com.hetao.xx.orm.UserVo;
import com.hetao.xx.service.UserManager;
import com.hetao.xx.utils.UtilList;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class DelActivity extends AppCompatActivity {

    @SuppressLint("NonConstantResourceId")
    @BindView(R.id.load_grid)
    GridView gridView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_load);
        ButterKnife.bind(this);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setTitle("输入昵称");


        final List<UserVo> userList = UserManager.loadUserList();
        if (UtilList.isNotEmpty(userList)) {

            final LoadPageAdapter adapter = new LoadPageAdapter(this, userList);
            gridView.setAdapter(adapter);

            gridView.setOnItemClickListener((parent, view, position, id) -> {

                UserManager.delUser(userList.get(position));
                userList.remove(position);
                adapter.notifyDataSetChanged();
            });
        }
    }


}
